import { defineStore } from "pinia";

// 选项式API

let useInfoStore = defineStore('info', {
  state: () => {
    return {
      count: 99,
      arr: [1,2,3,4,5,6,7,8,9,10]
    }
  },
  actions: {
    updateCount(a:number, b:number) {
      this.count += a;
      this.count += b;
    }
  },
  getters: {
    total():number {
      const result = this.arr.reduce((prev: number, next: number) => {
        return prev + next;
      }, 0);

      return result;
    },
    // fixme: 箭头函数内部的this变成了getters定义的这个对象
    // arrowFnTotal: ():number => {
    //   return this.total();
    // }
  }
});

export default useInfoStore;